package com.xianggu.designMode.orderMethod;

import com.xianggu.designMode.orderMethod.impl.AirConditioner;
import com.xianggu.designMode.orderMethod.impl.Curtain;
import com.xianggu.designMode.orderMethod.impl.Light;

// 具体命令：封装设备操作（组合命令）
class HomeModeCommand implements Command {
    private Light light;
    private AirConditioner ac;
    private Curtain curtain;
    private int prevTemp;  // 记录状态用于撤销

    public HomeModeCommand(Light light, AirConditioner ac, Curtain curtain) {
        this.light = light;
        this.ac = ac;
        this.curtain = curtain;
    }

    @Override
    public void execute() {
        light.on();
        prevTemp = 25;  // 假设默认温度
        ac.setTemp(prevTemp);
        curtain.close();
    }

    @Override
    public void undo() {
        light.off();
        ac.setTemp(prevTemp - 5);  // 恢复原温度
        System.out.println("撤销回家模式");
    }
}